home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_oth / formac / indenth.m
Text File  |  1987-11-13  |  10KB  |  398 lines

  1. ;**
  2. ;**        indenth.m:
  3. ;**    Templates for Fortran and Modula-2.  To use them, just use Setup
  4. ;**    to turn template editing on for Fortran and/or Modula-2, and
  5. ;**    start BRIEF with the -mindenth flag.
  6. ;**        Sample BPACKAGES=for,mod:t;c:s;m,h,asm:r
  7. ;**
  8. ;**    Note: these have been converted to BRIEF v2.0, but they do not
  9. ;**    support any more constructs than they did under BRIEF v1.3.
  10. ;**
  11.  
  12. #define    SEMI_COLON            1            ;** Code for semicolon.
  13.  
  14. #define    MIN_ABBREV            1            ;** Increase this to specify longer
  15.                                                 ;** minimum abbreviations.
  16. (extern        amt
  17.                 open_line
  18. )
  19.  
  20. (macro _init
  21.     (
  22.         (int        
  23.                     _for_template
  24.                _mod_template
  25.         )
  26.         (global    
  27.                     _for_template
  28.                _mod_template
  29.         )
  30.  
  31.         (keyboard_push)
  32.         (assign_to_key "#7181" ".for_indent")
  33.         (assign_to_key "#3849" "slide_in")
  34.         (assign_to_key "#3840" "slide_out")
  35.         (assign_to_key "#14624" ".for_abbrev")
  36.         (= _for_template (inq_keyboard))
  37.         (keyboard_pop 1)
  38.  
  39.         (keyboard_push)
  40.         (assign_to_key "#7181" ".mod_indent")
  41.         (assign_to_key "#3849" "slide_in")
  42.         (assign_to_key "#3840" "slide_out")
  43.         (assign_to_key "#14624" ".mod_abbrev")
  44.         (= _mod_template (inq_keyboard))
  45.         (keyboard_pop 1)
  46.     )
  47. )
  48.  
  49. ;**
  50. ;**        .for_template_first, .mod_template_first:
  51. ;**
  52. ;**        These macros are called by the BPACKAGES parser in language.m.
  53. ;**    They initialize the local keymaps for the various indenting functions.
  54. ;**
  55.  
  56. (macro .for_template_first
  57.     (
  58.         (use_local_keyboard _for_template)
  59.         (returns "")
  60.     )
  61. )
  62.  
  63. (macro .mod_template_first
  64.     (
  65.         (use_local_keyboard _mod_template)
  66.         (returns "")
  67.     )
  68. )
  69.  
  70. ;**
  71. ;**        Template editing macros.
  72. ;**
  73.  
  74. (macro .for_abbrev
  75.     (
  76.         (if (|| (== (read 1) "\n") (== (read 1) " "))
  77.             (
  78.                 (string        line)
  79.  
  80.                 (int            loc startloc)
  81.  
  82.             (inq_position NULL startloc)
  83.                 (save_position)
  84.                 (beginning_of_line)
  85.                 (= line (read))
  86.                 (restore_position)
  87.  
  88.                 (if (= loc (search_string "[~ \t\n]" line))
  89.                     (
  90.                         (int        length)
  91.  
  92.                         (= line (+ "ß" (substr line loc (+ (- startloc loc) 1))))
  93.                         (= line (substr line 1 (- (strlen line) 1)))
  94.  
  95.                         (if (&& (< MIN_ABBREV (strlen line))
  96.                                 (= loc (search_string line "ßdo ßif () thenßelse ßelseif () thenß" length 0)))
  97.                             (
  98.                                 (string        completion)
  99.  
  100.                                 (= completion (substr "ßdo ßif () thenßelse ßelseif () thenß" (+ loc length)))
  101.                                 (= completion (substr completion 1 (- (index completion "ß") 1)))
  102.                                 (insert completion)
  103.  
  104.                                 (if (== (substr line 2 1) "d")
  105.                                     (
  106.                                         (save_position)
  107.                               (.for_indent)
  108.                                         (insert "continue")
  109.                               (.for_indent)
  110.                                         (restore_position)
  111.                                     )
  112.                                 ;else
  113.                                     (if (== (substr line 2 1) "i")
  114.                                         (
  115.                                             (save_position)
  116.                                  (.for_indent)
  117.                                             (insert "endif")
  118.                                  (.for_indent)
  119.                                          (restore_position)
  120.                                             (move_rel 0 -6)
  121.                                         )
  122.                                     ;else
  123.                               (if (== (substr line 2 1) "e")
  124.                                  (
  125.                                     (if (== (substr line 2 5) "elsei")
  126.                                        (
  127.                                           (save_position)
  128.                                           (.for_indent)
  129.                                           (restore_position)
  130.                                           (move_rel 0 -6)
  131.                                        )
  132.                                     )
  133.                                  )
  134.                               ;else
  135.                                            (if (!= loc 1)
  136.                                                (search_back ")")
  137.                                            )
  138.                               )
  139.                                     )
  140.                                 )
  141.                             )
  142.                         ;else
  143.                             (self_insert)
  144.                         )
  145.                     )
  146.                 ;else
  147.                     (self_insert)
  148.                 )
  149.             )
  150.         ;else
  151.             (self_insert)
  152.         )
  153.     )
  154. )
  155.  
  156.  
  157. (macro .for_indent
  158.     (
  159.         (int        curr_indent_col        ;** Current unmodified indent col.
  160.                     following_position    ;** Column of end of line following cursor.
  161.                     curr_col                    ;** Column cursor is on when called.
  162.                     curr_line                ;** Column line is on when called.
  163.                     what_is_char_1            ;** End of first line's character identifier.
  164.                     what_is_char_2            ;** End of second line's indentifier.
  165.         )
  166.         (string    ch
  167.                following_string)        ;** All characters following the cursor.
  168.  
  169. ;**
  170. ;**        Gather information on the two previous non-blank lines.
  171. ;**
  172.  
  173.         (inq_position curr_line curr_col)
  174.         (end_of_line)
  175.         (inq_position NULL following_position)
  176.         (= following_position (- curr_col (-- following_position)))
  177.  
  178.         ;**        If there are characters following the cursor, save them in
  179.         ;**    following_string.
  180.  
  181.         (if (<= following_position 0)
  182.             (
  183.                 (int        non_blank_pos)
  184.  
  185.                 (move_rel 0 -1)
  186.                 (drop_anchor)
  187.                 (move_rel 0 following_position)
  188.                 (= following_string (read))
  189.  
  190.                 (if (= non_blank_pos (search_string "[~ \t]" following_string))
  191.                     (= following_string (substr following_string non_blank_pos))
  192.                 )
  193.                 (delete_block)
  194.             )
  195.         )
  196.         (if (search_back "<*\\c[~ \t\n]")
  197.             (
  198.                 (inq_position NULL curr_indent_col)
  199.             )
  200.         ;else
  201.             (
  202.                 (= curr_indent_col 1)
  203.             )
  204.         )
  205.         (move_abs curr_line curr_col)
  206.  
  207. ;**
  208. ;**        We've determined the last two non-blank lines' last characters
  209. ;**    as well as the column position of the first non-blank character.
  210. ;**    Now we position the cursor on the new line's proper level.
  211. ;**
  212.  
  213.         (if (< curr_indent_col 1)
  214.             (= curr_indent_col 1)
  215.         )
  216.         (insert "\n")
  217.         (move_abs 0 curr_indent_col)
  218.  
  219.         (if (<= following_position 0)
  220.             (
  221.                 (= following_string (substr following_string 1 (- (strlen following_string) 1)))
  222.                 (insert following_string)
  223.                 (move_abs 0 curr_indent_col)
  224.             )
  225.         )
  226.     )
  227. )
  228.  
  229.  
  230.  
  231. (macro .mod_abbrev
  232.    (
  233.         (if (|| (== (read 1) "\n") (== (read 1) " "))
  234.             (
  235.                 (string        line)
  236.  
  237.                 (int            loc 
  238.                         temp
  239.                         startloc)
  240.  
  241.             (inq_position NULL startloc)
  242.                 (save_position)
  243.                 (beginning_of_line)
  244.                 (= line (read))
  245.                 (restore_position)
  246.  
  247.                 (if (= loc (search_string "[~ \t\n]" line))
  248.                     (
  249.                         (int        length)
  250.  
  251.                   (= line (+ "ß" (substr line loc (+ (- startloc loc) 1))))
  252.                         (= line (substr line 1 (- (strlen line) 1)))
  253.  
  254.                   (if (&& (< MIN_ABBREV (strlen line))
  255.                                 (= loc (search_string line "ßCASE () OFßLOOPßWHILE () DOßREPEAT ßIF () THENßELSEßELSIF () THENß" length 0)))
  256.                             (
  257.                                 (string        completion)
  258.  
  259.                         (= completion (substr "ßCASE () OFßLOOPßWHILE () DOßREPEAT ßIF () THENßELSEßELSIF () THENß" (+ loc length)))
  260.                                 (= completion (substr completion 1 (- (index completion "ß") 1)))
  261.                                 (insert completion)
  262.  
  263.                                 (if (== (substr line 2 1) "R")
  264.                                     (
  265.                                         (save_position)
  266.                                         (open_line)
  267.                               (move_rel 0 (- 0 amt))
  268.                               (insert "UNTIL ()\;")
  269.                                          (search_back ")")
  270.                                     )
  271.                                 ;else
  272.                                     (if (index "IWLC" (substr line 2 1))
  273.                               (
  274.                                             (save_position)
  275.                                             (open_line)
  276.                                  (move_rel 0 (- 0 amt))
  277.                                  (insert "END\;")
  278.                                             (restore_position)
  279.                                             (if (!= (substr line 2 1) "L")
  280.                                     (search_back ")")
  281.                                  )
  282.                               )
  283.                                     ;else
  284.                               (if (== (substr line 2 1) "E")
  285.                                  (
  286.                                     (if (== (substr line 2 5) "ELSI")
  287.                                                   (search_back ")")
  288.                                     )
  289.                                  )
  290.                               ;else
  291.                                            (if (!= loc 1)
  292.                                                (search_back ")")
  293.                                            )
  294.                               )
  295.                                     )
  296.                                 )
  297.                             )
  298.                         ;else
  299.                             (self_insert)
  300.                         )
  301.                     )
  302.                 ;else
  303.                     (self_insert)
  304.                 )
  305.             )
  306.         ;else
  307.             (self_insert)
  308.         )
  309.    )
  310. )
  311.  
  312.  
  313. (macro .mod_indent
  314.    (
  315.         (int        curr_indent_col        ;** Current unmodified indent col.
  316.                     following_position    ;** Column of end of line following cursor.
  317.                     curr_col                    ;** Column cursor is on when called.
  318.                     curr_line                ;** Column line is on when called.
  319.                     what_is_char_1            ;** End of first line's character identifier.
  320.                     what_is_char_2            ;** End of second line's indentifier.
  321.         )
  322.         (string    ch
  323.                following_string)        ;** All characters following the cursor.
  324.  
  325. ;**
  326. ;**        Gather information on the two previous non-blank lines.
  327. ;**
  328.  
  329.         (inq_position curr_line curr_col)
  330.         (end_of_line)
  331.         (inq_position NULL following_position)
  332.         (= following_position (- curr_col (-- following_position)))
  333.  
  334.         ;**        If there are characters following the cursor, save them in
  335.         ;**    following_string.
  336.  
  337.         (if (<= following_position 0)
  338.             (
  339.                 (int        non_blank_pos)
  340.  
  341.                 (move_rel 0 -1)
  342.                 (drop_anchor)
  343.                 (move_rel 0 following_position)
  344.                 (= following_string (read))
  345.  
  346.                 (if (= non_blank_pos (search_string "[~ \t]" following_string))
  347.                     (= following_string (substr following_string non_blank_pos))
  348.                 )
  349.                 (delete_block)
  350.             )
  351.         )
  352.         (if (search_back "<*\\c[~ \t\n]")
  353.             (
  354.                 (inq_position NULL curr_indent_col)
  355.                 (end_of_line)
  356.                 (search_back "[~ \t\n]")
  357.                 (= what_is_char_2 (|| (== "\;" (= ch (read 1))) (== ch "|")))
  358.                 (next_char)
  359.                 (delete_to_eol)
  360.             )
  361.         ;else
  362.             (
  363.                 (= what_is_char_2 SEMI_COLON)
  364.                 (= curr_indent_col 1)
  365.             )
  366.         )
  367.         (move_abs curr_line curr_col)
  368.  
  369. ;**
  370. ;**        We've determined the last two non-blank lines' last characters
  371. ;**    as well as the column position of the first non-blank character.
  372. ;**    Now we position the cursor on the new line's proper level.
  373. ;**
  374.  
  375.         (if (!= curr_indent_col 1)
  376.             (
  377.                 (if (!= what_is_char_2 SEMI_COLON)
  378.                   (+= curr_indent_col amt)
  379.                 )
  380.             )
  381.         )
  382.         (if (< curr_indent_col 1)
  383.             (= curr_indent_col 1)
  384.         )
  385.         (insert "\n")
  386.         (move_abs 0 curr_indent_col)
  387.  
  388.         (if (<= following_position 0)
  389.             (
  390.                 (= following_string (substr following_string 1 (- (strlen following_string) 1)))
  391.                 (insert following_string)
  392.                 (move_abs 0 curr_indent_col)
  393.             )
  394.         )
  395.    )
  396. )
  397.  
  398.